
import * as network_utils from '../../../../http/NetworkUtils';
import * as constants from '../../../../common/Constants';
import * as umfutils from '../../../../utils/UmfUtils';

Page({

    data: {
        //查询月份
        profitDate: '',

        profitTotal: _getProfitTotal(),
        profitSub1: _getProfitSub1(),
        profitSub2: _getProfitSub2()
    },

    onLoad: function (options) {
        this.setData({
            profitDate: options.profitDate
        });

        this._requestPos();
    },

    tapDetail: function (event) {
        let profitType = event.currentTarget.dataset.tag;
        wx.navigateTo({
            url: './posDetails/posDetails?profitType=' + profitType + "&date=" + this.data.profitDate
        });
    },

    /**
     * 查询POS汇总数据
     * @private
     */
    _requestPos() {
        // let params = {
        //     date: "2016-12",
        //     // date: this.data.profitDate
        // };
        let params = {
            date: this.data.profitDate
        };

        network_utils.buildRequest(constants.Interfaces.FUNC_S_POS_OR, params, {
            doHttpSucess: (response) => {
                if (constants.RetCodes.SUCCESS === response.retCode) {
                    this.setData({
                        profitTotal: _getProfitTotal(response),
                        profitSub1: _getProfitSub1(response),
                        profitSub2: _getProfitSub2(response)
                    });
                    return true;
                }
                return false;
            }
        }).send();
    }
});

function _getProfitTotal(result) {
    let arr = [];
    arr.push({title: "总交易额(元)", value: result ? umfutils.fentoyuan(result["amount"]) : "0.00"});
    arr.push({title: "分润总计(元)", value: result ? umfutils.fentoyuan(result["sumFullAmt"]) : "0.00"});
    arr.push({title: "实际分润金额(元)", value: result ? umfutils.fentoyuan(result["sumTrueAmt"]) : "0.00"});
    return arr;
}

function _getProfitSub1(result) {
    let arr = [];
    arr.push({title: "T1全额分润(元)", tag: constants.ProfitTypes.T1.name, value: result ? umfutils.fentoyuan(result["t1FullAmt"]) : "0.0"});
    arr.push({title: "T1实际分润(元)", tag: constants.ProfitTypes.T1.name, value: result ? umfutils.fentoyuan(result["t1TrueAmt"]) : "0.0"});
    arr.push({title: "D0全额分润(元)", tag: constants.ProfitTypes.D0.name, value: result ? umfutils.fentoyuan(result["d0FullAmt"]) : "0.0"});
    arr.push({title: "D0实际分润(元)", tag: constants.ProfitTypes.D0.name, value: result ? umfutils.fentoyuan(result["d0TrueAmt"]) : "0.0"});
    arr.push({title: "D1全额分润(元)", tag: constants.ProfitTypes.D1.name, value: result ? umfutils.fentoyuan(result["d1FullAmt"]) : "0.0"});
    arr.push({title: "D1实际分润(元)", tag: constants.ProfitTypes.D1.name, value: result ? umfutils.fentoyuan(result["d1TrueAmt"]) : "0.0"});
    arr.push({title: "直连全额分润(元)", tag: constants.ProfitTypes.DERECT.name, value: result ? umfutils.fentoyuan(result["zhilianFullAmt"]) : "0.0"});
    arr.push({title: "直连实际分润(元)", tag: constants.ProfitTypes.DERECT.name, value: result ? umfutils.fentoyuan(result["zhilianTrueAmt"]) : "0.0"});
    return arr;
}

function _getProfitSub2(result) {
    let arr = [];
    arr.push({title: "微信分润", tag: constants.ProfitTypes.WECHAT.name, value: result ? umfutils.fentoyuan(result.wechatProfit) : "0.0"});
    arr.push({title: "支付宝分润", tag: constants.ProfitTypes.ALIPAY.name, value: result ? umfutils.fentoyuan(result.alipayProfit) : "0.0"});
    return arr;
}